23 thoughts on “C# NPOI – How to Read and Write Excel files in .NET

  1. Thank you for this excellent article. However, you should always add all essentials coding parts. Without the required ‘using’ clauses, one won’t get the classes definitions identified by the IDE.

    1. Hey Rajesh- Thanks for the inputs! Glad it helped you! Sure will update the ‘using’ statements used in the article.

  2. hi thanks for the exemples.
    i have question : what is the best way to do to use a template xlsx file, fill it without saving the template, and save the work in a new xlsx file?
    thanks for the help

    1. Hi Khalid- Thanks for your query. You can use the read method above for reading the template and fill it in memory as table or dataset (if file size is not big ) later use in-memory data to save it as new excel.

  3. Hello Sir .. I got a very big help from this article . Thumbs up.
    Can you please a code snippet where i can format cell

    1. Hello Naved, Thank you. glad it helped you. do you have any specific requirements for cell formatting, let me know I shall put some samples on it.

  4. Do you know how I can get help on using NPOI from vba? I’ve downloaded and built NPOI.dll, but I don’t know how to call it and I can’t find any examples of vba usage. My purpose is to build an excel file from an Access runtime on a machine where office is not installed.

    1. Hi- Thanks for your query. I have not tried NPOI using VBA yet. I shall post more on it if happen to get more details.

  5. Thanks for your examples. I just want to point out that this is a coding issue:

    if (cell == null || string.IsNullOrWhiteSpace(cell.ToString())) continue;
    {
    dtTable.Columns.Add(cell.ToString());
    }

      1. I have tried but not getting the correct result , If you know request to help
        Need to copy Excel Macro in object using C# ?

  6. Hello, I want to excel library with NPOI, EEPLUS, OpenXML..
    can i free to use it?

    i think that EEPLUS for a fee.

    1. Hey John- Thanks for your query! As I am aware OpenXML is free and Open-sourced from Microsft. For EPPULUS and NPOI kindly check their licensing terms and conditions. Have a good day!

  7. Hello, this is an excellent article, can you please show us example how to export byte[] array image to excel?

Leave a Reply

Your email address will not be published. Required fields are marked *